/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @author jkonopka
 * 
 */
public class InsertScriptRowGenerator implements IGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3105109958471155297L;
	private String table;
	private Map<String, Object> content;

	/**
	 * @param table
	 * @param content
	 */
	public InsertScriptRowGenerator(String table, Map<String, Object> content) {
		this.table = table;
		this.content = content;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.IGenerator#generate()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder result = new StringBuilder();
		result.append("INSERT INTO ");
		result.append(table);
		result.append(" ( ");

		final IGenerator colsGenerator = new InsertScriptColumnGenerator(content.keySet());
		result.append(colsGenerator.generate());

		result.append(" ) VALUES ( ");

		final List<Object> list = new ArrayList<Object>(content.values());
		final IGenerator valGenerator = new InsertScriptValueGenerator(list);
		result.append(valGenerator.generate());

		result.append(" ); ");
		return result.toString();
	}

}
